package com.whut.userservice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whut.clcommon.entity.Result;
import com.whut.userservice.domain.vo.UserFansAndAttentionsVO;
import com.whut.userservice.domain.vo.UserSimpleVO;
import com.whut.userservice.service.IUserFollowService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user/relation")
public class UserFollowController {

    @Resource
    private IUserFollowService userFollowService;

    @PostMapping("/follow")
    public Result<?> follow(@RequestParam Long followId){
        userFollowService.follow(followId);
        return Result.success();
    }

    @PostMapping("/unfollow")
    public Result<?> unfollow(@RequestParam Long followId) {
        userFollowService.unfollow(followId);
        return Result.success();
    }

    @GetMapping("/get_fans")
    public Result<Page<UserSimpleVO>> getFans(@RequestParam @NotNull Long userId,
                                        @RequestParam @NotNull Long page,
                                        @RequestParam @NotNull Long size) {
        return Result.success(userFollowService.getFans(userId, page, size, true));
    }

    @GetMapping("/get_attentions")
    public Result<Page<UserSimpleVO>> getAttentions(@RequestParam @NotNull Long userId,
                                                    @RequestParam @NotNull Long page,
                                                    @RequestParam @NotNull Long size) {
        return Result.success(userFollowService.getFans(userId, page, size, false));
    }

    @GetMapping("/get_fans_and_attention_count")
    public Result<UserFansAndAttentionsVO> getFansAndAttentionCount(@RequestParam @NotNull Long userId) {
        return Result.success(userFollowService.getFansAndAttentionCount(userId));
    }
}
